package com.example.boot.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import com.alibaba.druid.support.http.StatViewServlet;
//import com.alibaba.druid.support.http.WebStatFilter;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.boot.web.servlet.ServletRegistrationBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.sql.DataSource;
//import java.sql.SQLException;
//import java.util.Arrays;
//
///**
// * @author shkstart
// * @creat 2021-04-06-下午4:11
// */
////@Configuration
public class MyDataSourceConfig {
//    @Bean
//    @ConfigurationProperties("spring.datasource")//自动配置
//    public DataSource dataSource() throws SQLException {
//        //默认的自动配置是判断容器中没有才会陪@ConditionalOnMissingBean(Datasource.class)
//        DruidDataSource druidDataSource = new DruidDataSource();
//        //stat加入druid的sql监控功能,wall开启防火墙功能,setXXX的属性配置都可以在配置文件写
//        druidDataSource.setFilters("stat,wall");
//        return druidDataSource;
//    }
//
//    /**
//     * 配置druid的监控页功能
//     * @return
//     */
//    @Bean
//    public ServletRegistrationBean staViewServlet(){
//        StatViewServlet statViewServlet = new StatViewServlet();
//        ServletRegistrationBean<StatViewServlet> RegistrationBean = new ServletRegistrationBean<>(statViewServlet, "/druid/*");
//        RegistrationBean.addInitParameter("loginUsername","admin");
//        RegistrationBean.addInitParameter("loginPassword","123456");
//        return RegistrationBean;
//    }
///**
// * WebStatFilter用于采集web-jdbc关联监控的数据
// */
//    @Bean
//    public FilterRegistrationBean WebStatFilter(){
//        WebStatFilter webStatFilter = new WebStatFilter();
//        FilterRegistrationBean<WebStatFilter> webStatFilterFilterRegistrationBean = new FilterRegistrationBean<>(webStatFilter);
//        webStatFilterFilterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
//        //排除哪些请求不被监控
//        webStatFilterFilterRegistrationBean.addInitParameter("exclusins","*.js,*.gif,*.jpg,*.png,*.css,*.ico,druid/*");
//        return webStatFilterFilterRegistrationBean;
//    }
}
